package com.class3.team.fossilProject.Controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.class3.team.fossilProject.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.sql.DataSource;
import java.sql.*;


@RestController
@RequestMapping("/search")
public class SearchController {

    public static Integer sum_of_data = 100;

    @Autowired
    private BookService bookS;
 
    
    
    @GetMapping("/{type}")
    @ResponseBody
    public JSONArray getByType(@PathVariable String type){
        JSONArray res = new JSONArray();
        String lowertype = type.toLowerCase();
        for( Integer j = 1; j < sum_of_data; j++ ){
            JSONObject temp = bookS.getBookById(j);
            for(int i = 0;i < 2; i++){
                if(i==0){
                    temp.getJSONObject("properties").put("type", temp.getJSONObject("properties").get(lowertype));
                    res.add(temp);
                }

            }
        }
        return res;
    }

	
}
